package 算法;

import java.util.HashMap;

/**
 * 时间复杂度：O(nums.length)
 */
public class twosum {
    public int[] fastwithMap2(int[] nums,int target){
        HashMap<Integer, Integer> map = new HashMap<>();
        int[] result=new int[2];
        for(int i=0;i<nums.length;i++){
            if(map.containsKey(nums[i])){
                int anotherIndex=map.get(nums[i]);
                result[0]=anotherIndex;
                result[1]=i;
                break;
            }else{
                map.put(target-nums[i],i);
            }
        }
        return result;
    }
}
